<?php

namespace app\common\job;

use baidu\Ocpc;
use think\queue\Job;

/**
 * 百度营销回传
 * Class BaiduOcpc
 * @package app\common\job
 */
class BaiduOcpc
{
    /**
     * fire是消息队列默认调用的方法
     * @param Job $job 当前的任务对象
     * @param array|mixed $data 发布任务时自定义的数据
     */
    public function fire(Job $job, $data)
    {
        $token = $data['token'] ?? '';
        $logidUrl = $data['logidUrl'] ?? '';
        $newType = $data['newType'] ?? '';

        try {

            $this->getOcpc()->uploadConvertData($token, $logidUrl, $newType);
        } finally {

            $job->delete();
        }

    }

    private function getOcpc():Ocpc
    {
        return app(Ocpc::class);
    }
}
